﻿
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using KeRui.Common;
    using System.Collections.Generic;

    /// <summary>
    /// SellerHelper 的摘要说明
    /// </summary>
    public class SellerHelper
    {
        public SellerHelper()
        {
            
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }




        /// <summary>
        /// 检测会员登陆，如果失败并做相应
        /// </summary>
        public static void CheckMemberLogin()
        {
            if (KeRui.BLL.Account.GetLoginUserID() < 1)
            {
                string js = "";
                
                js = "alert('登陆已超时，请重新登录。');window.top.location.href = '/member/login.aspx?url=" + Utils.UrlEncode(PageRequest.GetRawUrl()) + "';";

                HttpContext.Current.Response.Write("<html><head><script language='javascript' type='text/javascript'>" + js + "</script></head></html>");
                HttpContext.Current.Response.End();
            }
        }


        /// <summary>
        /// 分类信息--检测会员登陆，如果失败并做相应提示
        /// </summary>
        public static void CheckMemberLogin_Info()
        {
            if (KeRui.BLL.Account.GetLoginUserID() < 1)
            {
                string js = "";

                js = "alert('登陆已超时，请重新登录。');window.top.location.href = 'login.aspx?url=" + Utils.UrlEncode(PageRequest.GetRawUrl()) + "';";

                HttpContext.Current.Response.Write("<html><head><script language='javascript' type='text/javascript'>" + js + "</script></head></html>");
                HttpContext.Current.Response.End();
            }
        }

        /// <summary>
        /// 添加系统日志
        /// </summary>
        /// <param name="Flag">模块</param>
        /// <param name="Log">日志</param>
        public static void AddLog(string Flag, string Log)
        {
            KeRui.BLL.AdminLog.Add(KeRui.BLL.Account.GetLoginUserID(), Flag, Log);
        }

        public static int GetSellerID()
        {
            int memberID = KeRui.BLL.Account.GetLoginUserID();
            KeRui.BLL.Seller bll = new KeRui.BLL.Seller();
            int sellerid = bll.GetSellerIDByUserid(memberID);
            return sellerid;
        }
        public static int GetUserID()
        {
            return KeRui.BLL.Account.GetLoginUserID();
        }
        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="url"></param>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageCS"></param>
        /// <returns></returns>
        public static string showSplitPage(string url, int PageIndex, int PageSize, int PageCS)
        {
            string str = "";
            int PageCounts = 0;//总页数

            if (PageCS % PageSize == 0)
                PageCounts = PageCS / PageSize;
            else
                PageCounts = PageCS / PageSize + 1;


            if (PageCounts <= 1)
            {
                return str;
            }

            int start = (PageIndex - 4) > 0 ? (PageIndex - 4) : 1;
            int end = (PageIndex + 4) < PageCounts ? (PageIndex + 4) : PageCounts;
            if ((PageIndex - 1) < 4)
            {
                start = 1;
                end = (start + 8) < PageCounts ? (start + 8) : PageCounts;
            }
            if ((PageCounts - PageIndex) < 4)
            {
                end = PageCounts;
                start = (end - 9) > 0 ? (end - 9) : 1;
            }
            str += "<div id='col01right04'><ul>";
            if (PageIndex != 1)
                str += @"<li><a href='" + url.Replace("{0}", "1") + @"'><img align='absmiddle' src='/Manage/Pic/Icons/arrow/arrow_first.gif'>&nbsp;首页</a>&nbsp;</li><li><a href='" + url.Replace("{0}", (PageIndex - 1).ToString()) + "'><img align='absmiddle' src='/Manage/Pic/Icons/arrow/arrow_prev.gif'>&nbsp;上一页</a>&nbsp;</li>";
            for (int i = start; i <= end; i++)
            {
                if (i == PageIndex)
                    str += @"<li class=""curr-page"">" + i.ToString() + "</li>";
                else
                    str += @"<li><a href='" + url.Replace("{0}", i.ToString()) + "'>" + i.ToString() + "</a></li>";
            }
            if (PageIndex < PageCounts)
            {
                str += @"<li>&nbsp;<a href='" + url.Replace("{0}", (PageIndex + 1).ToString()) + "'><img align='absmiddle' src='/Manage/Pic/Icons/arrow/arrow_next.gif'>&nbsp;下一页</a></li>";
                str += @"<li>&nbsp;<a href='" + url.Replace("{0}", (PageCounts).ToString()) + "'><img align='absmiddle' src='/Manage/Pic/Icons/arrow/arrow_last.gif'>&nbsp;末页</a></li>";
            }
            str += string.Format(
                "</ul>");

            str += "</div>";
            return str;
        }


    }
